from joblib import load
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
import tensorflow as tf

class xiangmu7(object):
    
    def __init__(self):
        self.loaded_model = tf.keras.models.load_model("./xm7/my_model.keras")
        self.scaler = load("./xm7/scaler.joblib")
        
        
    def get_hourly_trend(self):
        """模型预测结果获取"""
        
        
        n_steps = 7
        df_pivot = pd.read_csv("./xm7/scenic_data.csv")
        # latest_data = df_pivot.iloc[-n_steps:].values
        x_values =df_pivot.iloc[-n_steps:]
        x_values.iloc[-1,x_values.columns.get_loc('count')]=0
        x_lasterst=x_values.values
        latest_data = x_lasterst.reshape(1, n_steps,x_lasterst.shape[1])
        
        # 预测与反归一化
        predicted = self.loaded_model.predict(latest_data)
        predicted_count = self.scaler.inverse_transform(predicted)
        predicted_count[predicted_count < 0] = 0
        
        hourly_trend = predicted_count[0].astype(int).tolist()
        print (hourly_trend)
        
        
if __name__ == '__main__':
    hbs = xiangmu7()
    hbs.get_hourly_trend()